﻿using Model.Sys;
using SqlserverManager;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeFirstSqlSugar
{
    /// <summary>
    /// 种子数据得建表完再插入,没有EF hasdata(new List<menu>)方法
    /// </summary>
    public class AddTableCodeFirst : IAddTableCodeFirst
    {
        public readonly IDbConnectionFactory dbConnectionFactory;
        public AddTableCodeFirst(IDbConnectionFactory dbConnectionFactory)
        {
            this.dbConnectionFactory = dbConnectionFactory;
        }

        public async void CreatDb()
        {
            var db = dbConnectionFactory.CreateDbContext();
            //建库：如果不存在创建数据库存在不会重复创建 createdb
            db.DbMaintenance.CreateDatabase();
            
        }

        /// <summary>
        /// sqlsugar版的数据迁移
        /// </summary>
        public void Update_database()
        {
            //var db = dbConnectionFactory.CreateDbContext();
            //db.CodeFirst.InitTables(typeof(CeshiSqlsugarCodefirst));
            //CeshiSqlsugarCodefirst ceshiSqlsugarCodefirst = new CeshiSqlsugarCodefirst()
            //{
            //    Id = "123",
            //    Name = "123s"
            //};
            //await db.Insertable<CeshiSqlsugarCodefirst>(ceshiSqlsugarCodefirst).ExecuteCommandAsync();
        }

    }
}
